/**
 * Created by cjd on 2016/6/24.
 */
angular.module("app").controller("topic.list.Ctrl", ["$scope", "topic", function ($scope, topic) {
    $scope.search = {display: 1, key: ""};
    $scope.searchTopicList = function () {
        topic.getList({}, {display: $scope.search.display, key: $scope.search.key}, function (data) {
            if (data.statusCode == 0) {
                $scope.topicList = data.data;
            } else {
                alert(data.statusMessage)
            }
        })
    };
    $scope.topicDisplay = function(item){
        if(confirm("确定执行该操作吗?")){
            if(item.display){
                /*置为无效*/
                topic.invalid({}, {id: item.id}, function (data) {
                    if (data.statusCode == 0) {
                        alert("操作成功!");
                        $scope.searchTopicList();
                    } else {
                        alert(data.statusMessage)
                    }
                })
            }
            else{
                topic.effective({}, {id: item.id}, function (data) {
                    if (data.statusCode == 0) {
                        alert("操作成功!");
                        $scope.searchTopicList();
                    } else {
                        alert(data.statusMessage)
                    }
                })
            }
        }
    };
    $scope.updateTop = function (item) {
        if(confirm("确定执行该操作吗?")){
            topic.updateTop({}, {id: item.id}, function (data) {
                if (data.statusCode == 0) {
                    alert("操作成功!");
                    $scope.searchTopicList();
                } else {
                    alert(data.statusMessage)
                }
            })
        }
    };
    $scope.topicEdit = function (item) {
        location.href = "#/home/topic/info/" + item.id;
    };
    $scope.topicCreate = function () {
        location.href = "#/home/topic/info/";
    };
    $scope.searchTopicList();
}]);